package com.qf.springMybatisRandomUser.until;

import cn.hutool.core.util.RandomUtil;
import com.qf.springMybatisRandomUser.entity.User;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author 刘欣
 * @createTime 2023/1/2 18:37
 * @description
 */
public class RanDomeUserUntil {
    private static String str = "qwertyuioopasdfghjklzxcvbnm";

    public static User getUser() throws ParseException {
        User user = new User();
        user.setName(getUserName());
        user.setPassword(getUserPassowrd());
        user.setSex(getUserSex());
        user.setBirthday(getUserBirthday());
        user.setRegistTime(getUserRegistTime());
        user.setAuthor(getUserAuthor());
        user.setStatus(getUserStatus());
        user.setAccount(getUserAccount());
        return user;
    }

    public static String getUserName() {
        return RandomUtil.randomString(str, 5);
    }

    public static String getUserPassowrd() {
        return RandomUtil.randomString(20);
    }

    public static String getUserSex() {
        return RandomUtil.randomString("10", 1);
    }

    public static Date getUserBirthday() throws ParseException {
        return randomTime();
    }

    public static Date getUserRegistTime() throws ParseException {
        return randomTime();
    }

    public static String getUserAuthor() {
        return RandomUtil.randomString(str, 10);
    }

    public static Integer getUserStatus() {
        return Integer.parseInt(RandomUtil.randomString("10", 1));
    }

    public static Integer getUserAccount() {
        return RandomUtil.randomInt(999999999);
    }


    public static Date randomTime() throws ParseException {
        Random rndYear = new Random();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int year = rndYear.nextInt(18) + 2000;  //生成[2000,2017]的整数；年
        Random rndMonth = new Random();
        int month = rndMonth.nextInt(12) + 1;   //生成[1,12]的整数；月
        Random rndDay = new Random();
        int Day = rndDay.nextInt(30) + 1;       //生成[1,30)的整数；日
        Random rndHour = new Random();
        int hour = rndHour.nextInt(23);       //生成[0,23)的整数；小时
        Random rndMinute = new Random();
        int minute = rndMinute.nextInt(60);   //生成分钟
        Random rndSecond = new Random();
        int second = rndSecond.nextInt(60);    //生成秒
        return simpleDateFormat.parse(year + "-" + month + "-" + Day + " " + hour + ":" + minute + ":" + second);
    }

    public static List<User> getRandomUsers(Integer num) throws ParseException {
        List<User> users = new ArrayList<>();
        for (Integer i = 0; i < num; i++) {
            users.add(getUser());
        }
        return users;
    }

}
